package com.me.model;

import com.me.model.viewmodel.GoodsViewModel;

import java.math.BigDecimal;
import java.util.UUID;

public class Goods {
    private String id;
    private String name;
    private String cover;
    private String image1;
    private String image2;
    private BigDecimal price;
    private String intro;
    private int stock;
    private String typeId;

	public Goods() {
	}


	public void fromView(GoodsViewModel vm) {
		if (vm.getId() == "" || vm.getId() == null) {
			this.id = UUID.randomUUID().toString();
		}
		this.name = vm.getName();
		this.cover = vm.getCover() == "" || vm.getCover() == null ? this.cover : vm.getCover();
		this.image1 = vm.getImage1() == "" || vm.getImage1() == null ? this.image1 : vm.getImage1();
		this.image2 = vm.getImage2() == "" || vm.getImage2() == null ? this.image2 : vm.getImage2();
		this.price = BigDecimal.valueOf(vm.getPrice());
		this.intro = vm.getIntro();
		this.stock = vm.getStock();
		this.typeId = vm.getTypeId();
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public String getTypeId() {
		return typeId;
	}

	public void setTypeId(String typeId) {
		this.typeId = typeId;
	}

	public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public String getImage1() {
        return image1;
    }

    public void setImage1(String image1) {
        this.image1 = image1;
    }

    public String getImage2() {
        return image2;
    }

    public void setImage2(String image2) {
        this.image2 = image2;
    }

    public float getPrice() {
        return price.floatValue();
    }

    public BigDecimal getDPrice() {
        return price;
    }

    public void setPrice(float price) {
        BigDecimal d = new BigDecimal(price);
        this.price = d;
    }

    public String getIntro() {
        return intro;
    }

    public void setIntro(String intro) {
        this.intro = intro;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

}
